package com.hx;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Huathy
 * @date 2021-10-11 23:32
 * @description
 */
@SuppressWarnings("all")
public class ServerSocketDemo2 {
    static ExecutorService executorService = Executors.newCachedThreadPool();;
    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(8888);
        while (true){
            Socket socket = serverSocket.accept();
//            new Thread(new SocketThread(socket)).start();   //不阻塞，可以解决IO阻塞问题。但线程不可控
            executorService.execute(new SocketThread(socket));  //线程可控的操作方式
        }
    }
}
